/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

package scenic.path;

import java.awt.Rectangle;
import java.awt.geom.AffineTransform;

/**
 * This class defines a path that can be used for stroking and filling.
 * A path consists of one or more subpaths. Each subpath consists
 * of one or more connected segments. There are different kinds 
 * of segments: straight lines, Bezier curves and elliptical arcs.
 * 
 * Path, subpaths and segments are constant. Their values cannot
 * be changed after they are created.
 * 
 */
public class GenericPath implements Path {
	private SubPath[] subPaths;
	
	/**
	 * Creates a path that has the given subpaths.
	 * 
	 * @param subPaths the subpaths.
	 */
	public GenericPath(SubPath[] subPaths) {
		this.subPaths = subPaths;
	}
		
	/**
	 * Gets the subpaths.
	 */
	public SubPath[] getSubPaths() {
		return (SubPath[])subPaths.clone();
	}

	/**
	 * Walks the given walker through the path.
	 * 
	 * @param walker the walker.
	 * @param error the error matrix.
	 */
	public void walk(PathWalker walker, AffineTransform errorMatrix, double error) {
		for(int i = 0; i < subPaths.length; i++)
			subPaths[i].walk(walker, errorMatrix, error);
	}
	
	/**
	 * Calculates the bounds of this path using the given transform.
	 * 
	 * @param transform the transform.
	 * @return the bounds.
	 */
	public Rectangle getBounds(AffineTransform transform) {
		Rectangle r = new Rectangle();
		
		for(int i = 0; i < subPaths.length; i++)
			subPaths[i].getBounds(transform, r);
		
		return r;
	}

	public boolean isConvex() {
		if(subPaths.length == 1)
			return subPaths[0].isConvex();
		return false;
	}
}
